package com.tanhua.manage.controller;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanhua.manage.pojo.RoleOpreation;
import com.tanhua.manage.service.RoleOpreationService;

import com.tanhua.manage.util.NoAuthorization;
import com.tanhua.manage.vo.RoleOperationVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @author 杨一帆
 * @date 2020/12/13  14:45
 */
@RestController
@RequestMapping("/role/opreation")
public class RoleOpreationController {
    @Autowired(required = true)
    private RoleOpreationService roleOpreationService;

    @GetMapping
    @NoAuthorization
    public IPage<RoleOpreation> findByPage(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                           @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "role", required = false) String role,
                                           @RequestParam(name = "opreation", required = false) String opreation,
                                           @RequestParam(name = "StartTime", required = false) Long startTime,
                                           @RequestParam(name = "endTime", required = false) Long endTime) {


        IPage<RoleOpreation> byPage = this.roleOpreationService.findByPage(page, pageSize, role, opreation, startTime, endTime);

        List<RoleOpreation> records = byPage.getRecords();
        for (RoleOpreation record : records) {
            String format = DateUtil.format(new Date(record.getCreatTime()), "yyyy-MM-dd");

            record.setCreated(format);
        }

//        IPage<RoleOperationVo> pageVo = null;
//        pageVo.setCurrent(byPage.getCurrent());
//        pageVo.setPages(byPage.getPages());
//        pageVo.setRecords(RoleOperationVo.formatToList(byPage.getRecords()));
//        pageVo.setSize(byPage.getSize());
//        pageVo.setTotal(byPage.getTotal());
        return byPage;

    }


    @GetMapping("/see/{id}")
    @NoAuthorization
    public Map<String, String> qureyOne(@PathVariable("id") Integer id) {
        return this.roleOpreationService.qureyOne(id);
    }


}
